package cn.iocoder.yudao.module.blog.controller.app.posteruser;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.blog.controller.admin.posteruser.vo.PosterUserCreateReqVO;
import cn.iocoder.yudao.module.blog.controller.admin.posteruser.vo.PosterUserRespVO;
import cn.iocoder.yudao.module.blog.controller.admin.posteruser.vo.PosterUserUpdateReqVO;
import cn.iocoder.yudao.module.blog.convert.posteruser.PosterUserConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.posteruser.PosterUserDO;
import cn.iocoder.yudao.module.blog.service.posteruser.PosterUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 海报个人信息")
@RestController
@RequestMapping("/blog/posteruser")
@Validated
@Slf4j
public class AppPosterUserController {

    @Resource
    private PosterUserService posterUserService;

    @GetMapping("/get-by-userid")
    @Operation(summary = "获得用户海报信息")
    @Parameter(name = "userId", description = "编号", required = true, example = "1024")
    public CommonResult<PosterUserRespVO> getPosterUser(@RequestParam("userId") Long userId) {
        PosterUserDO posterUser = posterUserService.getPosterUserByUserId(userId);
        return success(PosterUserConvert.INSTANCE.convert(posterUser));
    }

    @PostMapping("/create")
    @Operation(summary = "创建用户海报用户信息")
    public CommonResult<Long> createPosterUser(@Valid @RequestBody PosterUserCreateReqVO createReqVO) {
        return success(posterUserService.createPosterUser(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户海报用户信息")
    public CommonResult<Boolean> updatePosterUser(@Valid @RequestBody PosterUserUpdateReqVO updateReqVO) {
        posterUserService.updatePosterUser(updateReqVO);
        return success(true);
    }
}
